#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <stack>

using namespace std;

bool IsPopOrder(vector<int>& pushV, vector<int>& popV) {
    // write code here
    stack<int> v;
    int i = 0;
    int j = 0;

    while (i < popV.size()) {
        v.push(pushV[i]);

        while (!v.empty() && v.top() == popV.at(j)) {
            v.pop();
            j++;
            if (v.empty() && j == popV.size())
            {
                return true;
            }
        }
        i++;

    }
        return false;

}

int evalRPN(vector<string>& tokens) {

    stack<int> st;
    for (auto str : tokens)
    {
        if (str == "+" || str == "-" || str == "*" || str == "/")
        {
            int num1 = st.top();
            st.pop();
            int num2 = st.top();
            st.pop();

            int ret = 0;
            switch (str[0])
            {
            case '+':
                ret = num1 + num2;
                st.push(num1 + num2);
                break;
            case '-':
                ret = num1 - num2;
                st.push(num1 - num2);
                break;
            case '*':
                ret = num1 * num2;
                st.push(num1 * num2);
                break;
            case '/':
                ret = num1 / num2;
                st.push(num1 / num2);
                break;
            }
        }
        else
        {
            st.push(stoi(str));
        }
    }

    return st.top();
}
int main()
{

	/*std::stack<int, vector<int>> s1;
	s1.push(1);
	s1.push(2);
	s1.push(3);

	while (!s1.empty())
	{
		printf("%d ", s1.top());
		s1.pop();
	}*/

   /* vector<int> pushV;
    pushV.push_back(1);
    pushV.push_back(2);
    pushV.push_back(3);
    pushV.push_back(4);
    pushV.push_back(5);

    vector<int> popV;
    popV.push_back(1);
    popV.push_back(4);
    popV.push_back(2);
    popV.push_back(5);
    popV.push_back(3);

    printf("%d ", IsPopOrder(pushV, popV));*/

    //"4","13","5","/","+"
    vector<string> v;
    v.push_back("4");
    v.push_back("13");
    v.push_back("5");
    v.push_back("/");
    v.push_back("+");

    evalRPN(v);
	return 0;
}
